package com.yq233.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yq233.dao.UserDao;
import com.yq233.pojo.UserPojo;
import lombok.val;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserService {
    @Autowired
    UserDao userDao;

    public void addUsear(int id, String name, String password) {
        userDao.insert(new UserPojo(id, name, password));
    }

    public void delUser(int id) {
        userDao.deleteById(id);
    }

    public void delUserName(String username) {
        userDao.delete(new QueryWrapper<UserPojo>().like("username", username));
    }

    //查找数据
    public Object findUserName(String username) {
        val pojos = userDao.selectList(new QueryWrapper<UserPojo>().like("username", username));
        pojos.forEach(item -> {
            System.out.println(item);
        });
        return pojos;
    }

    //修改数据
    public void updataName(Integer id) {
        val userPojo = userDao.selectById(id);
        userPojo.setPassword("114514");
        userDao.update(userPojo, new QueryWrapper<UserPojo>().eq("id", id));
    }

}
